import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/dormitory/dormBedPerson/list',
  save='/dormitory/dormBedPerson/add',
  edit='/dormitory/dormBedPerson/edit',
  leave='/dormitory/dormBedPerson/leave',
  deleteOne = '/dormitory/dormBedPerson/delete',
  deleteBatch = '/dormitory/dormBedPerson/deleteBatch',
  importExcel = '/dormitory/dormBedPerson/importExcel',
  // exportXls = '/dormitory/dormBedPerson/exportXls',
  exportXls = '/dormitory/dormBedPerson/downloadTemplate',
  buildList = '/dormitory/dormBuild/list',
  storeyList = '/dormitory/dormStorey/list',
  roomList = '/dormitory/dormRoom/list',
  // bedList = '/dormitory/dormRoom/queryDormBedByMainId',
  bedList = '/dormitory/dormBedPerson/list',
  detailedList='/dormitory/dormRoom/detailedList',

}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});
export const detailedList = (params) =>
  defHttp.get({url: Api.detailedList, params});
export const buildList = (params) =>
  defHttp.get({url: Api.buildList, params});
export const storeyList = (params) =>
  defHttp.get({url: Api.storeyList, params});
export const roomList = (params) =>
  defHttp.get({url: Api.roomList, params});
export const bedList = (params) =>
  defHttp.get({url: Api.bedList, params});

/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

/**
 * 退房
 * @param params
 */
export const leave = (params, isUpdate) => {
  let url = Api.leave;
  return defHttp.post({url: url, params});
}

export const saveApi = (params, ) => {
  return defHttp.post({url: Api.save, params});
}